<?PHP

class OP_ArchivesWidget extends OP_WidgetTemplate{
	function render(){
		$title = empty( $this->values['title'] ) ? __( 'Archives' ) : apply_filters('widget_title', $values['title']);
		$c = $this->values['count'] ? '1' : '0';
		$d = $this->values['dropdown'] ? '1' : '0';

		echo $this->values['before_title'] . $title . $this->values['after_title'];
		
		if($d) {
			echo '<span class="select_title">',
					attribute_escape(__('Select Month')),
				'</span> ',
				'<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">',
				'<option value="">',
				wp_get_archives("type=monthly&format=option&show_post_count=$c"),
				'</option>',
				
			'</select>';
		} else {
			echo '<ul>',
				wp_get_archives("type=monthly&show_post_count=$c"),
				'</ul>';
		}
	}
	
	
	function do_post($post){
		$count = isset($post['count']);
		$dropdown = isset($post['dropdown']);
		$title = strip_tags(stripslashes($post["title"]));
	
		return compact( 'title','count','dropdown');
	}

	function options(){
		$title = attribute_escape($this->values['title']);
		
		$count = $this->values['count'] ? 'checked="checked"' : '';
		$dropdown = $this->values['dropdown'] ? 'checked="checked"' : '';
		
		echo '<p><label for="op_archives-title-'.$this->values['number'].'">'._e('Title:').' <input class="widefat" id="op_archives-title-'.$this->values['number'].'" name="widget_op_archives['.$this->values['number'].'][title]" type="text" value="'.$title.'" /></label></p>',
			'<p>',
				'<label for="op_archives-count-'.$this->values['number'].'">'._e('Show post counts').' </label><input class="checkbox" type="checkbox" '.$count.' id="op_archives-count-'.$this->values['number'].'" name="widget_op_archives['.$this->values['number'].'][count]" />',
				'<br />',
				'<label for="op_archives-dropdown">'._e('Display as a drop down').' </label><input class="checkbox" type="checkbox" '.$dropdown.' id="op_archives-dropdown-'.$this->values['number'].'" name="widget_op_archives['.$this->values['number'].'][dropdown]" />',
			'</p>';
	}
}

$widget = new OP_Widget('archives');
$widget->setMeta('OP Archives','A monthly archives of your blog\'s posts');
$widget->setDefaults(array('title'=>''));

$opw_archives = new OP_ArchivesWidget($widget);
add_action('widgets_init', array($opw_archives, 'init'));
?>